Have you heard of “code-movies” or “code-flipbooks”? Maybe not? This blog post will tell you what they are, point you to tools to build them, and showcase student work and their insights about building flipbooks.

I’ll use the terms ‘code-movies’ and ‘flipbooks’ interchangeably.

What are flipbooks?

Flipbooks help you communicate how to get from ‘A’ to ‘B’ using data manipulation, analysis, or visualization code pipelines. When using R markdown or Jupytr notebooks, we often see the input and output for a pipeline of steps. Having the inputs and outputs nearby is really helpful in communicating the big picture of what is being accomplished with a chunk of code.

But newcomers and even seasoned practitioners might have trouble figuring out what the individual steps in a pipeline accomplish. This is where flipbooks come in! They seek to illuminate what’s going on in each step of the pipeline or plot. Flipbooks do this by showing the within-pipeline output states as the code is built up.

Here’s an example - mouse over to see the movie effect:




Code-movies in recent presentations

The ‘flipbook’ or code-movie technique is one that you may have seen in coding presentations. Presenters know that showing a code pipeline as it is built helps audiences digest workflows. So it’s worth choreographing a set of slides to break down the build. If the alignment between slides is good — and if we don’t have disruptive slide transitions (wipes, spins, fades) — we get to enjoy a little movie: the coordinated evolution of code and output. Some examples are here:

Building flipbooks fast and reliably with {flipbookr}

While code-movies deliver helpful insight to consumers, putting together this code-movie experience can be time consuming. There’s a lot of copy-paste that has to happen to create the right partial code sequence – and you can mix yourself up trying to coordinate it (I’ve been there!).

The {flipbookr} package’s goal is to help create these easy-to-follow-along-with, step-by-step experiences — without the copy and paste pain! So all you need to do is write your pipeline once – then you can let {flipbookr} take over and create the coordinated evolution of code and output movie to communicate the process.

Basically {flipbookr}, with the rmarkdown slide show package xaringan, does three things:

  1. Parses an Rmd code pipeline from the chunk you indicate (you name the chunk)
  2. Identifies good break points in that code chunk pipeline; the default is finding balanced parentheses at the ends of lines.
  3. Spawns a bunch of code chunks with these partial builds of code, separated by slide breaks.
  4. Displays partial code and builds side by side and sequentially on html slides, giving us a movie-like experience .

There is so much decision-making packed into our code pipelines. The {flipbookr} project is about making it easy to bringing those decisions to light so they can be appreciated, examined, discussed, relived!

Taking {flipbookr} for a spin

After installing flipbookr install.packages("flipbookr") there are a couple of ways you might get started.

One way is using the Easy Flipbook Recipes guide. You’ll put together a basic flipbook with step-by-step instructions.

Alternatively, you can use the “A minimal flipbook” template that comes with the package. Using R Studio, with the installed package you can request the basic template with File -> New File -> Rmarkdown -> A Minimal Flipbook.

What to expect: insights and products using {flipbookr}

Before you start building your own flipbooks, it might also be useful to see some examples from some other folks.

Four of my graduate research assistants at the Unversity of Denver’s Korbel School of International Studies, with the support of an RConsortium Grant, have built several excellent flipbooks here, showcasing {gganimate}, {ggplot2} mapping, {tmap} and {magick}.

Here’s a comment from one of them about building flipbooks:

The process of producing a flipbook pushed me to think differently about both data wrangling and data visualization. It required me to be more deliberate in how I wrote and ordered my code, and it revealed redundancies and other inefficiencies in my script. The process also deepened my understanding of the commands that I employed by allowing me to see the output of each individual line of code. - Rachel

Conner - {tmap} View full size in new tab

Brit - {magick} View full size in new tab

Luca - {gganimate} View full size in new tab

Rachel - {maps w/ ggplot} View full size in new tab


Acknowledgements: {flipbookr} heroes

The {flipbookr} project has been fortunate to build on incredible tools, in particular {xaringan} and the Rmarkdown. It’s inspired by the amazing tools {flipbookr} aims to demo — particularly ggplot2 and tidyverse data manipulation pipelines.

Lots of folks have helped build {flipbookr}, especially Emi Tanaka and Garrick Aden-Buie, with visionary insights and ground-breaking work on the code-movie experience and automated code-movid builds in Xaringan.